package com.tuanbiao.presenter;

import android.text.TextUtils;

import com.abiao.lib_utils.StringUtils;
import com.hzjq.data.minbao.entity.AuthEntity;
import com.tuanbiao.base.mvp.BasePresenter;
import com.tuanbiao.controllers.AuthController;
import com.tuanbiao.data.callback.OnBaseResultCallback;

/**
 * @author abiao
 * @since 2022/4/24 10:36
 */
public class SequencePresenter extends BasePresenter<AuthController.Model, AuthController.SequenceView> implements AuthController.SequencePresenter {
    public SequencePresenter(AuthController.Model model, AuthController.SequenceView rootView) {
        super(model, rootView);
    }

    @Override
    public void downloadAuthFile(String code) {
        if (TextUtils.isEmpty(code)) {
            mRootView.showMessage("请输入验证码");
            return;
        }

        if (!TextUtils.isDigitsOnly(code) || StringUtils.length(code) != 6) {
            mRootView.showMessage("请输入六位数字验证码");
            return;
        }
        mModel.loadAuthByCode(code, new OnBaseResultCallback<AuthEntity>() {
            @Override
            public void onSuccess(AuthEntity entity) {
                mRootView.showMessage("下载完成");
            }

            @Override
            public void onFailed(String msg) {
                mRootView.showMessage(msg);
            }
        });
    }
}
